package com.ccloud.gen.action.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.ccloud.gen.properties.GeneratorProperties;

/**
 * @Version V1.0
 * @Project bigdata-cloud
 * @Title GunsGeneratorConfig
 * @Description 默认的代码生成的配置- 数据库配置
 * @Package com.ccloud.gen.action.config
 * @Date 2021/7/8 3:29 下午
 * @Copyright: 武汉大数据产业发展有限公司 All rights reserved.
 */
public class GunsGeneratorConfig extends AbstractGeneratorConfig {

    protected void globalConfig() {
        globalConfig.setOutputDir(GeneratorProperties.out_path);//写自己项目的绝对路径,注意具体到java目录
        globalConfig.setFileOverride(true);
        globalConfig.setEnableCache(false);
        globalConfig.setBaseResultMap(true);
        globalConfig.setBaseColumnList(true);
        globalConfig.setOpen(false);
        globalConfig.setAuthor(GeneratorProperties.author);
    }

    protected void dataSourceConfig() {
        dataSourceConfig.setDbType(DbType.MYSQL);
        dataSourceConfig.setDriverName(GeneratorProperties.jdbc_driver_name);
        dataSourceConfig.setUsername(GeneratorProperties.db_user);
        dataSourceConfig.setPassword(GeneratorProperties.db_password);
        dataSourceConfig.setUrl(GeneratorProperties.db_url);
    }

    protected void strategyConfig() {
        // 此处可以修改为您的表前缀
        strategyConfig.setTablePrefix(GeneratorProperties.table_prefix);
        strategyConfig.setNaming(NamingStrategy.underline_to_camel);
    }

    protected void packageConfig() {
        packageConfig.setParent(null);
        packageConfig.setEntity(GeneratorProperties.package_name + ".model");
        packageConfig.setMapper(GeneratorProperties.package_name + ".mapper");
        packageConfig.setXml(GeneratorProperties.package_name + ".mapper.mapping");
    }

    protected void contextConfig() {
        contextConfig.setProPackage(GeneratorProperties.pro_package_name);
        contextConfig.setCoreBasePackage("com.ccloud.common.core");
        contextConfig.setBizChName("逆向工程类");
        contextConfig.setBizEnName(GeneratorProperties.biz_name);
        contextConfig.setModuleName(GeneratorProperties.biz_name);
        contextConfig.setProjectPath(GeneratorProperties.out_path);//写自己项目的绝对路径
        contextConfig.setEntityName(GeneratorProperties.biz_name);
        sqlConfig.setParentMenuName(null);//这里写已有菜单的名称,当做父节点

        /**
         * mybatis-plus 生成器开关
         */
        contextConfig.setEntitySwitch(true);
        contextConfig.setDaoSwitch(true);
        contextConfig.setServiceSwitch(true);

        /**
         * guns 生成器开关
         */
        contextConfig.setControllerSwitch(true);
        contextConfig.setIndexPageSwitch(true);
        contextConfig.setAddPageSwitch(true);
        contextConfig.setEditPageSwitch(true);
        contextConfig.setDetailPageSwitch(true);
        contextConfig.setJsSwitch(true);
        contextConfig.setInfoJsSwitch(true);
        contextConfig.setSqlSwitch(true);
    }

    @Override
    protected void config() {
        globalConfig();
        dataSourceConfig();
        strategyConfig();
        packageConfig();
        contextConfig();
    }
}
